package com.dubbo.task;

import ch.qos.logback.core.util.TimeUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

@Component
public class TestTask {

    /**
     * 每隔2秒执行该方法
     */
    @Scheduled(cron = "*/2 * * * * ?")
    public void task1() {
        System.out.println(Thread.currentThread().getName()+":execute task1:"+ LocalDateTime.now());

    }

    /**
     * 每隔1秒执行该方法
     */
    @Scheduled(cron = "*/1 * * * * ?")
    public void task2() {
        System.out.println(Thread.currentThread().getName()+":execute task1:"+ LocalDateTime.now());
        try {
            TimeUnit.HOURS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
